package training;

import java.util.*;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_6_11_Training {
    //背包与魔法
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int M = scanner.nextInt();
        long K = scanner.nextLong();
        long[][] dp1 = new long[n+1][M+1];
        long[][] dp2 = new long[n+1][M+1];

        long[][] nums = new long[n+1][2];
        long max = -1;
        for (int i = 1; i <= n; i++) {
            nums[i][0] = scanner.nextLong();
            nums[i][1] = scanner.nextLong();
            max = Math.max(max, nums[i][1]);
        }


        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= M; j++) {
                dp2[i][j] = dp2[i-1][j];
                dp1[i][j] = dp1[i-1][j];
                if(j>=nums[i][0]) {
                    dp1[i][j] = Math.max(dp1[i][j], dp1[i-1][j-(int)nums[i][0]]+nums[i][1]);
                    dp2[i][j] = Math.max(dp2[i][j], dp2[i-1][j-(int)nums[i][0]]+nums[i][1]);
                }

                if(j>=nums[i][0]+K) {
                    dp2[i][j] = Math.max(dp2[i][j], dp1[i-1][(j-(int)nums[i][0]-(int)K)] + nums[i][1]*2);
                }
            }
        }

        System.out.println(Math.max(dp2[n][M], dp1[n][M]));
    }

    //小球称重
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        boolean[] nums = new boolean[n+1];
        boolean[] tmp = new boolean[n+1];
        for (int i = 0; i < m; i++) {
            int k = scanner.nextInt();
            int[] nums1 = new int[k+1];
            int[] nums2 = new int[k+1];
            for (int j = 1; j <= k; j++) {
                nums1[j] = scanner.nextInt();
            }
            for (int j = 1; j <= k; j++) {
                nums2[j] = scanner.nextInt();
            }
            char ch = scanner.next().charAt(0);
            if(ch=='=') {
                for (int j = 1; j <= k; j++) {
                    nums[nums1[j]] = true;
                    nums[nums2[j]] = true;
                    tmp = Arrays.copyOf(nums,nums.length);
                }
            }else if(ch=='<'){
                Arrays.fill(nums, true);
                for (int j = 1; j <= k; j++) {
                    if(tmp[nums1[1]]==false) {
                        nums[nums1[j]] = false;
                    }
                    tmp = Arrays.copyOf(nums,nums.length);
                }
            }else {
                Arrays.fill(nums, true);
                for (int j = 1; j <= k; j++) {
                    if(tmp[nums2[1]]==false) {
                        nums[nums2[j]] = false;
                    }
                    tmp = Arrays.copyOf(nums,nums.length);
                }
            }
        }
        long count = 0;
        for (int i = 1; i <= n; i++) {
            if(!nums[i]) {
                count++;
                //System.out.println(i);
            }
        }
        System.out.println(count);
    }

    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        HashSet<Integer> set = new HashSet<Integer>();
        HashSet<Integer> set2 = new HashSet<Integer>();
        for (int i = 0; i < m; i++) {
            int k = scanner.nextInt();
            List<Integer> list1 = new ArrayList<>();
            List<Integer> list2 = new ArrayList<>();
            for (int j = 1; j <= k; j++) {
                list1.add(scanner.nextInt());
            }
            for (int j = 1; j <= k; j++) {
                list2.add(scanner.nextInt());
            }
            char ch = scanner.next().charAt(0);
            if(ch=='=') {
                set2.addAll(list1);
                set2.addAll(list2);
            }else if(ch=='>') {
                if(set.isEmpty()) set.addAll(list2);
                else set.retainAll(list2);
                set2.addAll(list1);
            }else {
                if(set.isEmpty()) set.addAll(list1);
                else set.retainAll(list1);
                set2.addAll(list2);
            }
        }
        set.removeAll(set2);
        if(set.isEmpty()) System.out.println(n-set2.size());
        else System.out.println(set.size());
    }
}
